package com.study.spmongodb.wwj.thread2.char04;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/7 20:19
 */
public abstract class ObservableRunnable implements Runnable {
    protected LifeCycleListener listener;

    public ObservableRunnable(final LifeCycleListener listener) {
        this.listener = listener;
    }

    public ObservableRunnable() {
    }

    protected void notifyChange(final RunnableEvent event) {
        listener.onEvent(event);
    }

    public enum RunnableState {
        RUNNING, ERROR, DONE;
    }

    public static class RunnableEvent {

        private final RunnableState state;

        private final Thread thread;

        private final Throwable casue;

        public RunnableEvent(RunnableState state, Thread thread, Throwable casue) {
            this.state = state;
            this.thread = thread;
            this.casue = casue;
        }

        public RunnableState getState() {
            return state;
        }

        public Thread getThread() {
            return thread;
        }

        public Throwable getCasue() {
            return casue;
        }
    }
}
